package com.lxw.manage_media.controller;

import com.lxw.api.media.MediaUploadControllerApi;
import com.lxw.framework.domain.media.request.QueryMediaFileRequest;
import com.lxw.framework.model.response.QueryResponseResult;
import com.lxw.manage_media.service.IMediaUploadService;
import com.lxw.framework.domain.media.response.CheckChunkResult;
import com.lxw.framework.model.response.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class MediaUploadController implements MediaUploadControllerApi {
    @Autowired
    IMediaUploadService mediaUploadService;

    @Override
    @PostMapping("upload/register")
    public ResponseResult register(String fileMd5, String fileName, Long fileSize, String mimetype, String fileExt) {

        return mediaUploadService.register(fileMd5,fileName,fileSize,mimetype,fileExt);
    }

    @Override
    @PostMapping("upload/checkchunk")
    public CheckChunkResult checkchunk(String fileMd5, Integer chunk, Integer chunkSize) {
        return mediaUploadService.checkchunk(fileMd5,chunk,chunkSize);
    }

    @Override
    @PostMapping("upload/uploadchunk")
    public ResponseResult uploadchunk(MultipartFile file, Integer chunk, String fileMd5) {
        return mediaUploadService.uploadchunk(file,chunk,fileMd5);
    }

    @Override
    @PostMapping("upload/mergechunks")
    public ResponseResult mergechunks(String fileMd5, String fileName, Long fileSize, String mimetype, String fileExt) {
        return mediaUploadService.mergechunks(fileMd5,fileName,fileSize,mimetype,fileExt);
    }

    @Override
    @GetMapping("file/list/{page}/{pageSize}")
    public QueryResponseResult findList(@PathVariable Integer page,@PathVariable Integer pageSize, QueryMediaFileRequest qpr) {


        return mediaUploadService.findList(page,pageSize,qpr);
    }

    @Override
    @GetMapping("file/process/{mediaId}")
    public ResponseResult process(@PathVariable String mediaId) {

        return mediaUploadService.process(mediaId);
    }
}
